$NG.AllReady(function (page, { useAction, useBeforeClick, useValuesChange, useClick, useUpdateRow, subscribe, useUpdateRows }) {
    const user = $NG.getUser()
    const mstform = $NG.getCmpApi("p_form_pyclsh_m")

    const dataMap = {
        "6870000000000396": "tabPanel_tabItem",
        "6870000000000397": "tabPanel_tabItem_1",
        "6870000000000398": "tabPanel_tabItem_2",
        "6870000000000399": "tabPanel_tabItem_3",
        "6870000000000400": "tabPanel_tabItem_4"
    };

    if (page.oType == 'add' || page.oType == 'edit') {
        $NG.updateState((updater) => {
            updater.data.p_form_pyclsh_m.setProps({
                u_tbnd: {
                    label: String(new Date().getFullYear()),
                    value: String(new Date().getFullYear())
                }
            })
        })
    }

    useBeforeClick(() => {
        const u_tbnd = mstform.getItem("u_tbnd").getValue()
        if (!u_tbnd) {
            $NG.alert("请先选择填报年度！")
            return false
        }
        return true
    }, 'addrow')

    useValuesChange(() => {
        const phid = mstform.getItem("u_cllb").getValue()
        if (!phid) return
        selectTabs(dataMap[phid])
    }, "p_form_pyclsh_m.u_cllb")
    const u_cllb = mstform.getItem("u_cllb").getValue()
    selectTabs(dataMap[u_cllb])
    // 隐藏切换tabs
    function selectTabs(key) {
        const tabs = $NG
            .getCompMap()
            .get("__Tabs__")[0]
            .getApi();

        tabs.updateItems((innerItems, activeKey) => {
            return [...innerItems.filter((item) => {
                if (item.name == key) {
                    return item
                }
            })];
        });

        tabs.setActiveKey(key);
    }
})